package com.sinopac.model.core;

import java.util.ResourceBundle;

import netfusion.jbranch.database.DataAccessManager;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;

import com.sinopac.tableBean.TbLogs;
import com.sinopac.util.IdUtil;


public class ModelCore extends DataAccessManager{
	protected Logger logger;
	protected IdUtil idUtil;
	protected final static String USER_ROLES = "user_roles";
	protected final static String YES_OR_NO = "Yes_or_No";
	protected final static String OTP_STATUS = "otp_status";
	protected final static String TOKEN_STATUS = "token_status";
	protected final static String JOB_CODE = "job_code";
	protected final static String LOGIN_PLATFORM = "login_platform";
	protected final static String LOGIN_RESULT = "login_result";
	protected final static String TOKEN_SYN = "TokenSyn_return_code";
	
	protected String getRecentOperator(String custId) {
		StringBuffer  sql = new StringBuffer();
		sql.append("SELECT TOP 1 l.operator ");
		sql.append("FROM customers c ");
		sql.append("LEFT JOIN logs l ");
		sql.append("ON c.customer_id = l.customer_id ");
		sql.append("WHERE  c.customer_id = ? ");
		sql.append("ORDER  BY l.log_time ");
		setObject(0, custId);
		TbLogs logs = (TbLogs)super.exeQuery(sql.toString(), TbLogs.class).get(0);
		return logs.getOperator();
	}
	
	protected String getText(String type,String code){
		String result = null;
		ResourceBundle reesource = ResourceBundle.getBundle("resources.message");
		if(StringUtils.isNotBlank(type)){
			result = String.format("%s_%s", type,code);
		}else if(StringUtils.isNotBlank(code)){
			result = code;
		}else{
			return "";
		}
		return reesource.getString(result);
	}
}
